﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.Collections;

namespace EveServer
{
    public partial class Form1 : Form
    {
        const int BufferSize = 8192;
        private TcpListener Listener;
        private List<RemoteClient> Clients;
          

        public Form1()
        {
            InitializeComponent();
            Listener = new TcpListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6934));
            Clients = new List<RemoteClient>();
        }

        /// <summary>
        /// 启动服务器
        /// </summary>
        /// <param name="sender">发送者</param>
        /// <param name="e">事件</param>
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            ShowMessage("服务器启动中......");
            ShowMessage("监听IP：" + Listener.LocalEndpoint.ToString());
            Listener.Start();
            Thread AcceptThread = new Thread(AcceptClient);
            ShowMessage("服务器启动完毕！");
        }

        private void AcceptClient()
        {
            while(true)
            {
                TcpClient remoteClient = Listener.AcceptTcpClient();
                ShowMessage("接受来自客户端的连接！");
                ShowMessage("客户端IP：" + remoteClient.Client.RemoteEndPoint.ToString());
                Clients.Add(new RemoteClient(remoteClient));
            }
            
        }

        public void ShowMessage(string s)
        {
            this.listBoxControl1.Items.Add(s);
        }

        private void listBoxControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
